package com.zhuoyue.system.domain.dto;

import com.zhuoyue.common.constant.ResultCode;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;


/**
 * @author zhanghui
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ControllerResult implements Serializable {
    private Boolean success;
    private String msgCode;
    private String msg;
    private Object dataObject;

    public static ControllerResult toReturnSuccess(String msg, Object data) {
        return new ControllerResult(true, ResultCode.SUCCESS, msg, data);
    }

    public static ControllerResult toReturnSuccess(String msg) {
        return new ControllerResult(true, ResultCode.SUCCESS, msg, null);
    }

    public static ControllerResult toParamError(String msg) {
        return new ControllerResult(false, ResultCode.PARAM_ERROR, msg, null);
    }

    public static ControllerResult toSysError(String msg) {
        return new ControllerResult(false, ResultCode.SYS_ERROR, msg, null);
    }

    public static ControllerResult toError(String msg, String msgCode) {
        return ControllerResult.builder().success(false).msg(msg).msgCode(msgCode).build();
    }

    public static ControllerResult toTokenExpired(String msg) {
        return toError(msg, ResultCode.TOKEN_EXPIRET);
    }
}
